<#macro pagination id method page>
<div id="${id}" class="table-responsive">
    <div id="sample-table-2_wrapper" class="dataTables_wrapper" role="grid">
        <#nested>
        <input type="hidden" id="currentPage" value="${page.currentPage}">
        <input type="hidden" id="totalPages" value="${page.totalPages}">
        <input type="hidden" id="totalSize" value="${page.totalSize}">
        <!--分页-->
        <div class="row">
            <div class="col-sm-6">
                <div class="dataTables_info" id="sample-table-2_info">共${page.totalSize}条记录</div>
            </div>
            <div class="col-sm-6">
                <div class="dataTables_paginate paging_bootstrap">
                    <ul class="pagination">
                        <#if page.currentPage == 1>
                        <li class="prev disabled">
                            <a href="javascript:void(0);">
                                <i class="icon-double-angle-left"></i>
                            </a>
                        </li>
                        <#else>
                        <li class="prev">
                            <a href="javascript:Pagination${id}.gotoPage('prev', '${page.currentPage}', '${page.totalSize}');">
                                <i class="icon-double-angle-left"></i>
                            </a>
                        </li>
                        </#if>
                        <#list 1..page.totalPages as i>
                        <li <#if page.currentPage == i>class="active"</#if>>
                            <a href="javascript:void(0);" class="goToPage">${i}</a>
                        </li>
                        </#list>
                        <#if page.currentPage == page.totalPages>
                        <li class="next disabled">
                            <a href="javascript:void(0);">
                                <i class="icon-double-angle-right"></i>
                            </a>
                        </li>
                        <#else>
                        <li class="next">
                            <a href="javascript:Pagination${id}.gotoPage('next', '${page.currentPage}', '${page.totalSize}');">
                                <i class="icon-double-angle-right"></i>
                            </a>
                        </li>
                        </#if>
                    </ul>
                </div>
            </div>
        </div>
        <!--分页end-->
    </div>
    <script>
        var pageData = {};
        // 调用分页
        $(".pagination").delegate(".goToPage","click",function(){
            Pagination${id}.gotoPage($(this).text(), $("#currentPage").val(), $("#totalSize").val());
        });
        // 分页
        if (!this.Pagination${id} ) {
            this.Pagination${id} = {}
            
            // 分页处理方法
            Pagination${id}.gotoPage = function(action, c, t) {
                var page = {};
                var currentInt = parseInt(c);
                
                // 当总记录数量小于等于每页记录数量时，分页动作无效
                if (parseInt(t) <= 5 && action != 'refresh' || currentInt < 1) {
                    return;
                }
                
                page.currentPage = currentInt;
                
                if ("prev" == action && currentInt > 1) {
                    page.currentPage = currentInt - 1;
                } else if ("next" == action) {
                    page.currentPage = currentInt + 1;
                } else if (action.match("\\d+")) {
                    page.currentPage = action;
                }
                
                $.ajax({
                    url : '${method}',
                    type : 'POST',
                    data : page,
                    success : function(res) {
                        var str = res.replace(new RegExp("<script(.|\s)*?\/script>", "ig"), "");
                        var startindex = str.indexOf('<div id="${id}" class="table-responsive">');
                        var endindex   = str.lastIndexOf("<span id='flag'></span>");
                        var tempstr = str.substring(startindex,endindex);
                        $("#${id}").html(tempstr);
                    }
                });
            }
        }
    </script>
</div>
<span id='flag'></span>
</#macro>